﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using OMOMLibrary.Cities;
using OMOMLibrary.Units;

namespace OMOMLibrary.Grid{

    public class Grid{

        private Cell[,] cells;

        public Cell[,] Cells
        {
          get { return cells; }
          set { cells = value; }
        }

        public Grid(int x,int y) {
            this.cells = new Cell[x,y];
        }

        public void addCity(City c,Position p) {
            Cell cell = cells[p.X, p.Y];
            if (cell.City != null)
                throw new CantPlaceException();
            cell.City = c;
        }

        public void delCity(Position p) {
            Cell cell = cells[p.X, p.Y];
            cell.City = null;
        }

        public void addUnit(Position p, Unit u) {
            cells[p.X, p.Y].addUnit(u);
        }

        public void delUnit(Position p, Unit u) {
            cells[p.X, p.Y].delUnit(u);
        }

        public void moveUnit(Position from, Position to, Unit u) {
            delUnit(from,u);
            addUnit(from, u);
        }

    }
}
